<?php
/*
 * @Author: your name
 * @Date: 2021-10-09 14:09:58
 * @LastEditTime: 2021-11-08 09:18:51
 * @LastEditors: 乔
 * @Description: In User Settings Edit
 * @FilePath: \tp30\app\admin\controller\Order.php
 */

namespace app\admin\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Order extends BaseController
{
    public function orderDetail()
    {
        return view();
    }
    public function orderList()
    {
        $get = Request::get();

        $where = [];
        if (isset($get['keywords']) && !empty($get['keywords'])) $where['order_sn'] = $get['keywords'];  //['o.order_sn', 'like', "%{$get['keywords']}%"];
        if (isset($get['timeq']) && $get['timeq'] != "") $where['timeq']            = $get['timeq'];     //['o.addtime', '< TIME', $get['timeq']];
        if (isset($get['timeh']) && $get['timeh'] != "") $where['timeh']            = $get['timeh'];     //['o.addtime', '> TIME', $get['timeh']];
        if (isset($get['statuss']) && !empty($get['statuss'])) $where['status']     = $get['statuss'];   //['o.status', 'in', $get['statuss']];
        if (isset($get['prq']) && $get['prq'] != "") $where['prq']                  = $get['prq'];       //['o.amount', '>', $get['prq']];
        if (isset($get['prh']) && $get['prh'] != "") $where['prh']                  = $get['prh'];       //['o.amount', '<', $get['prh']];
        //if (isset($get['prq']) && $get['prq']!="" && $get['prh']=="")$where[] = ['o.amount','BETWEEN',[$get['prq'],0]];
        //if (isset($get['prh']) && $get['prh']!="" && $get['prq']=="")$where[] = ['o.amount','BETWEEN',[$get['prh'],0]];
        //if (isset($get['prq']) && isset($get['prh']) && $get['prh']!="" && $get['prq']!="")$where[] = ['o.amount','BETWEEN',[$get['prq'],$get['prh']]];
        //if (isset($get['timeq']) && $get['timeq']!="" && $get['timeh']=="")$where[] = ['o.addtime','BETWEEN TIME',[$get['timeq'],time()]];
        //if (isset($get['timeh']) && $get['timeh']!="" && $get['timeq']=="")$where[] = ['o.addtime','BETWEEN TIME',[$get['timeh'],time()]];
        //if (isset($get['timeq']) && isset($get['timeh']) && $get['timeh']!="" && $get['timeq']!="")$where[] = ['o.addtime','BETWEEN TIME',[$get['timeq'],$get['timeh']]];

        $list = \app\admin\model\Order::getOrderList($where, $get);
        // $list=Db::name('order')
        //     ->field('o.id,o.order_sn,o.uid,o.amount,o.addtime,o.status,o.remark,u.uname,s.order_status')
        //     ->alias('o')
        //     ->where($where)
        //     ->join('user u', 'o.uid=u.id')
        //     ->join('order_status s','o.status=s.status_id')
        //     ->paginate([
        //         'list_rows'=> 5,
        //         'var_page' => 'page',
        //         'query'=>$get,
        //     ]);
        $status = \app\admin\model\OrderStatus::getOrderStatusList();
        // $status = Db::name('order_status')
        //     ->select()
        //     ->toArray();

        View::assign($get);
        View::assign('list', $list);
        View::assign('status', $status);

        return view();
    }
}
